#include <iostream>
#include <cmath>
#include <iomanip>

class Complex
{
private:
    double real;
    double imaginary;

public:
    Complex(double r = 0, double i = 0) : real(r), imaginary(i) {}

    Complex(double r) : real(r), imaginary(0) {}

    Complex(int r) : real(r), imaginary(0) {}
    Complex operator-() const
    {
        return Complex(-real, -imaginary);
    }
    Complex operator~() const
    {
        return Complex(real, -imaginary);
    }

    friend double abs(Complex &c)
    {
        return std::sqrt(c.real * c.real + c.imaginary * c.imaginary);
    }

    friend std::ostream &operator<<(std::ostream &os, const Complex &c);

    Complex operator+(const Complex &other) const
    {
        return Complex(real + other.real, imaginary + other.imaginary);
    }

    Complex operator-(const Complex &other) const
    {
        return Complex(real - other.real, imaginary - other.imaginary);
    }

    Complex operator*(const Complex &other) const
    {
        double newReal = real * other.real - imaginary * other.imaginary;
        double newImaginary = real * other.imaginary + imaginary * other.real;
        return Complex(newReal, newImaginary);
    }

    Complex operator/(const Complex &other) const
    {
        double denominator = other.real * other.real + other.imaginary * other.imaginary;
        double newReal = (real * other.real + imaginary * other.imaginary) / denominator;
        double newImaginary = (imaginary * other.real - real * other.imaginary) / denominator;
        return Complex(newReal, newImaginary);
    }

    friend Complex operator+(double realNum, const Complex &c);
    friend Complex operator+(const Complex &c, double realNum);
    friend Complex operator-(double realNum, const Complex &c);
    friend Complex operator-(const Complex &c, double realNum);
    friend Complex operator*(double realNum, const Complex &c);
    friend Complex operator*(const Complex &c, double realNum);
    friend Complex operator/(double realNum, const Complex &c);
    friend Complex operator/(const Complex &c, double realNum);
};

std::ostream &operator<<(std::ostream &os, const Complex &c)
{
    if (c.real == 0 && c.imaginary == 0)
    {
        os << 0.00;
        return os;
    }
    if (c.real != 0 && c.imaginary == 0)
    {
        os << std::fixed << std::setprecision(2) << c.real;
        return os;
    }
    if (c.real == 0 && c.imaginary != 0)
    {
        os << std::fixed << std::setprecision(2) << c.imaginary << 'i';
        return os;
    }
    os << std::fixed << std::setprecision(2) << c.real;
    if (c.imaginary > 0)
        os << " + ";
    if (c.imaginary < 0)
        os << " - ";
    if (c.imaginary != 0)
        os << std::fixed << std::setprecision(2) << std::abs(c.imaginary) << "i";
    return os;
}

Complex operator"" i(unsigned long long Im)
{
    return Complex(0, static_cast<double>(Im));
}

Complex operator"" i(long double Im)
{
    return Complex(0, static_cast<double>(Im));
}

Complex operator+(double realNum, const Complex &c)
{
    return Complex(realNum + c.real, c.imaginary);
}

Complex operator+(const Complex &c, double realNum)
{
    return Complex(realNum + c.real, c.imaginary);
}
Complex
operator-(double realNum, const Complex &c)
{
    return Complex(realNum - c.real, -c.imaginary);
}
Complex operator-(const Complex &c, double realNum)
{
    return Complex(c.real - realNum, -c.imaginary);
}
Complex
operator*(double realNum, const Complex &c)
{
    return Complex(realNum * c.real, realNum * c.imaginary);
}
Complex operator*(const Complex &c, double realNum)
{
    return Complex(realNum * c.real, realNum * c.imaginary);
}
Complex
operator/(double realNum, const Complex &c)
{
    double denominator = c.real * c.real + c.imaginary * c.imaginary;
    double newReal = (realNum * c.real) / denominator;
    double newImaginary = (-realNum * c.imaginary) / denominator;
    return Complex(newReal, newImaginary);
}
Complex operator/(const Complex &c, double realNum)
{
    double newReal = c.real / realNum;
    double newImaginary = c.imaginary / realNum;
    return Complex(newReal, newImaginary);
}
